﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Https;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace https
{
    public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseKestrel(opt=>
                {
                   
                    opt.Listen(IPAddress.Any, 443, op =>
                    {
                        var ada = new HttpsConnectionAdapterOptions();
                        ada.ServerCertificate = new X509Certificate2("D:\\tmp\\localhost.pfx", "wshy89");
                        ada.CheckCertificateRevocation = true;
                        ada.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
                        ada.ClientCertificateValidation=((certificate2, chain, arg3) =>
                        {
                            
                            return true;
                        });
                        op.UseHttps(ada);
//                        op.UseHttps()
                    });
                })
                .UseStartup<Startup>()
//                .UseUrls("https://*:443")
                .Build();
    }
}
